import { http } from '@/utils/request/common'

enum Urls {
	login = 'mini/login',
	loginSms = '/login/login_sms',
	sendCode = 'mini/login/send_sms',
	sendForgetSms = '/login/send_forget_sms',
	modifyPassword = '/login/modify_pass',
	salesmanLogin = 'salesman/login',
	salesmanSendCode = 'salesman/send_sms',
	driverLogin = 'driver/login/wxLogin'
}

// 登录
type LoginFn = (data : any, mode : 'password' | 'code') => Promise<any>
export const login : LoginFn = (data : any, mode : 'password' | 'code') => {
	const url = {
		1: Urls.login,
		2: Urls.salesmanLogin,
		3: Urls.driverLogin,
	}
	const feach = {
		password: () => http.post(url[data.scene_id], data),
		code: () => http.post(Urls.loginSms, data)
	}
	return feach[mode]()
}

// 发送验证码
export const sendCode = (param) => http.get(Urls.salesmanSendCode, param)

export const sendForgetSms = (data) => http.post(Urls.sendForgetSms, data)

export const modifyPassword = (data) => http.post(Urls.modifyPassword, data)